﻿using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;
using System.Configuration;

namespace KPI.Utility
{
    /// <summary>
    /// Dependence Injection Container
    /// </summary>
    public class DependenceInjectionContainer
    {
        private static readonly IUnityContainer container = new UnityContainer().LoadConfiguration();

        /// <summary>
        /// Prevents a default instance of the <see cref="DependenceInjectionContainer"/> class from being created.
        /// </summary>
        private DependenceInjectionContainer()
        {
            UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
            section.Configure(container);
        }

        /// <summary>
        /// Resolves instance from container.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T Resolve<T>()
        {
            return container.Resolve<T>();
        }

        /// <summary>
        /// Gets the unity container.
        /// </summary>
        public static IUnityContainer UnityContainer
        {
            get
            {
                return container;
            }
        }
    }
}
